﻿using System;
using System.Collections;
using System.Collections.Generic;
using com.tdb.foundation;
using Script;
using Script.Function.PoisonGame.Data;
using Script.Function.Posion.Data;
using UnityEngine;

public class GameLogicModel
{
    private List<CardData> _cards;

    private List<PlayerData> _players;

    public void Init()
    {
        GenCard();
        _players = new List<PlayerData>();
    }
    
    public void PlayerJoin(PlayerData player)
    {
        _players.Add(player);
    }
    
    /// <summary>
    /// 生成新卡
    /// </summary>
    public void GenCard()
    {
        _cards = new List<CardData>();
        foreach (CardColorType color in Enum.GetValues(typeof(CardColorType)))
        {
            if (color == CardColorType.Posion)
            {
                for (int i = 0; i < Const.PosionCardNum; i++)
                {
                    _cards.Add(new CardData(color, Const.PosionCardNumType));
                }
            }
            else
            {
                for (int i = 0; i < Const.CardGeneralNumType.Length; i++)
                {
                    int numTypeOfCard = Const.CardGeneralNumType[i];
                    int numOfCard = numTypeOfCard == Const.SpecialCardNumType
                        ? Const.SpecialCardNum
                        : Const.GeneralCardNum;
                    for (int j = 0; j < numOfCard; j++)
                    {
                        _cards.Add(new CardData(color, numTypeOfCard));
                    }
                }
            }
        }
        _cards.Shuffle();
    }
    

    public void DealCard()
    {
        int totalCardsNum = _cards.Count;
        int handCardNum = totalCardsNum / _players.Count;
        for (int i = 0; i < _players.Count; i++)
        {
            _players[i].SetHandCard(_cards.GetRange(i * handCardNum, handCardNum));
        }
        // view事件触发？maybe
    }

    public void PlayCard()
    {
        
    }

    public void ResultSettlement()
    {
        
    }
}
